<template>
    <div class="ServerStateInformation">
        <el-row class="serStateLine-box">
            <el-col :span="8" class="serStateName">
                <p>运行时间</p>
            </el-col>
            <el-col :span="16" class="serStateData">
                <span class="lableNumber">
                    {{ osData.SYSUPTIME? osData.SYSUPTIME : " " }}
                </span>
            </el-col>
        </el-row>
        <el-row class="serStateLine-box">
            <el-col :span="8" class="serStateName">
                <p>当前时间</p>
            </el-col>
            <el-col :span="16" class="serStateData">
                <span class="lableNumber">
                    {{ osData.HRSYSTEMDATE? osData.HRSYSTEMDATE : " " }}
                </span>
            </el-col>
        </el-row>
        <el-row class="serStateLine-box">
            <el-col :span="8" class="serStateName">
                <p>系统会话</p>
            </el-col>
            <el-col :span="16" class="serStateData">
                <span class="lableNumber">
                    {{ osData.HRSYSTEMNUMUSERS? osData.HRSYSTEMNUMUSERS : (osData.HRSYSTEMNUMUSERS === 0?'0':" ") }}
                </span>
            </el-col>
        </el-row>
        <el-row class="serStateLine-box">
            <el-col :span="8" class="serStateName">
                <p>系统进程</p>
            </el-col>
            <el-col :span="16" class="serStateData">
                <span class="lableNumber">
                    {{ osData.HRSYSTEMPROCESSES? osData.HRSYSTEMPROCESSES : " " }}
                </span>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import { fetchData } from '@/api/index.js';
import bus from 'common/bus.js';

export default {
    data() {
        return {
            postData: {
                opera: 'ospanlinfo',
                curPage: 1,
                pageSize: 20,
                sort: {
                    sortColumn: '',
                    sortOrders: ''
                },
                filtersType: 'fuzzyquery',
                filters: {
                    "monid":""
                },
            },
            timerName: 'ServerStateInformation',
            timerEventName: 'timerServerStateInformation',
            timerInterval: 1000 * 60,
            selectedMonID: {},
            osData: {}
        }
    },
    created() {
        bus.$on('selectedMonIDServer', msg => {
            this.resetData();

            this.selectedMonID = msg;
            this.postData.filters.monid = this.selectedMonID.selectedOSMonID;
            this.getData();
        });

        bus.$emit('timerNewTodo', {
            name: this.timerName,
            eventName: this.timerEventName,
            interval: this.timerInterval,
            intervalNow: 0
        });

        bus.$on(this.timerEventName, msg => {
            if (msg.isGetData) {
                this.resetData();

                this.getData();
            }
        });
        
    },
    mounted() {

    },
    computed: {
        postDataFn() {
            return {
                postData : JSON.stringify(this.postData)
            }
        }
    },
    methods: {
        getData(){
            fetchData(
                this.postDataFn
            ).then((res) => {
                if (res.data.length > 0) {
                    this.osData = res.data[0];
                }
            });
        },
        resetData() {
            this.osData = {};
        }
    },
    beforeDestroy() {
        bus.$emit('timerNewTodo', {
            name: this.timerName
        });
    },
    watch:{
        
    }
}
</script>

<style scoped>
.ServerStateInformation{
    padding: 0px 5px;
    height: calc(100% - 22px - 8px);
    text-align: center;
    color: aliceblue;
}
.ServerStateInformation > div {
    height: calc(100% / 4);
    border-top: 1px solid rgb(4, 44, 119);
    overflow: hidden;
}

.ServerStateInformation > div > div {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-right: 1px solid rgb(4, 44, 119);
}
.ServerStateInformation > div > div:last-child {
    border-right: none;
}

.lableNumber{
    width: auto;
    overflow: hidden;
}
</style>    